﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using TinyForum.Domain.Model;
using System.Data.SqlClient;

namespace TinyForum.DBTool
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void CreateDatabaseSchema(object sender, EventArgs e)
        {
            try
            {
                Configuration cfg = new Configuration();
                //cfg.AddAssembly(typeof(User).Assembly);
                cfg.AddAssembly(typeof(Account).Assembly);
                cfg.Configure();
                SchemaExport se = new SchemaExport(cfg);
                se.Execute(false, true, false);
                MessageBox.Show("Success", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void InitializeDatabase(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Are you sure?", 
                    "Confirmation", 
                    MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)
                {
                    Configuration cfg = new Configuration();
                    //cfg.AddAssembly(typeof(User).Assembly);
                    cfg.AddAssembly(typeof(Account).Assembly);
                    cfg.Configure();
                    SchemaExport se = new SchemaExport(cfg);
                    se.Drop(false, true);
                    MessageBox.Show("Success", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
